package com.atguigu.redisdemo;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisSentinelPool;

import java.util.HashSet;
import java.util.Set;

public class MySentinel {
    public static void main(String[] args) {
        //1.1配置哨兵地址
        Set<String> sentinels = new HashSet<>();
        sentinels.add("192.168.1.102:26379");
        //1.2配置线程池
        GenericObjectPoolConfig config = new  JedisPoolConfig();
        config.setMaxTotal(10);
        config.setMinIdle(2);
        config.setMaxIdle(5);
        //1.创建哨兵线程池对象,配置哨兵地址和线程池
        JedisSentinelPool pool = new JedisSentinelPool("Mymaster",sentinels,config);
        //2.从线程池拿到哨兵
        Jedis jedis = pool.getResource();
        String ping = jedis.ping();
        System.out.println(ping);
        //3.归还线程
        jedis.close();
    }
}
